<?php
	if(!isset($_REQUEST['ajax'])){ $_REQUEST['ajax'] = "";}
	if($_REQUEST['ajax']!=true) include 'header.tpl.php';
	//include 'project_panel.tpl.php';
?>
	<h2><?php echo $this->language['project'];?> : <font color=red><?php echo $this->item['pName'];?></font></h2>
	<div class="row">
		<div class="col-lg-12">
			<ul class="shortcut-buttons-set">
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>'><span>
					<i class="aicon-textscan"></i>
					<?php echo $this->language['detail'];?></span></a>
				</li>
				<?php if($_SESSION['userId'] == 1): ?>
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>&mod=salaries'><span>
					<i class="aicon-dollarmulti"></i>
					Hoa hồng</span></a>
				</li>
				<?php endif;?>
				<?php if(check_permission('project_view') && $this->item['pParent'] == 0){ ?>
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>&mod=bussiness'><span>
					<i class="aicon-chart"></i>
					<?php echo $this->language['bussiness'];?></span></a>
				</li>
				<?php }?>
				<?php if($this->item['pParent'] == 0):?>
				<li>
					<a class="shortcut-button" href='#project_create/pid=<?php echo $this->item['pId'];?>'><span>
					<i class="aicon-projectnew"></i>
					Tạo dự án con</span></a>
				</li>
				<?php endif;?>
			</ul>
		</div>
	</div>
	<input type="hidden" id="pidhid" name="pidhid" value="<?php echo $this->item['pId'];?>">
	<div class="row">
		<div class="col-lg-4">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-money"></i> <?php echo $this->language['salary_system'];?></div>
				</div>
				<div class="panel-body">
					<form action="javascript:setProjectCredit();" class="form-horizontal">
						<div class="form-group">
							<label class="col-lg-4 control-label"><?php echo $this->language['project_price'];?></label>
							<div class="col-lg-8 input-group">
								<input class="form-control" type="text" name="pCredit" id="pCredit" value="<?php echo number_format($this->item['pCredit'],0,'.',',');?>" />
								<span class="input-group-addon">VNĐ</span>
							</div>
						</div>
						<div class="form-group">
							<label class="col-lg-4 control-label"><?php echo $this->language['project_salary'];?></label>
							<div class="col-lg-8 input-group">
								<input class="form-control" type="text" name="pProfitCredit" id="pProfitCredit" value="<?php echo number_format($this->item['pProfitCredit'],0,'.',',');?>" />
								<span class="input-group-addon">VNĐ</span>
							</div>
						</div>
						<?php if(check_permission('project_salary_edit')){ ?>
						<div class="form-group">
							<div class="col-lg-offset-4 col-lg-8">
								<button class="col-offset-4 btn btn-primary" type="submit"><?php echo $this->language['update'];?></button>
							</div>
						</div>
						<?php } ?>
					</form>
					<form action="javascript:setPercentCredit();" class="form-horizontal">
						<?php foreach($this->users as $row){ ?>
						<div class="form-group">
							<label class="col-lg-6 control-label"><?php echo $row['uFullname'];?></label>
							<div class="col-lg-6">
								<div class="input-group">
									<input class="form-control" type="text" name="pPercentCredit" id="pPercentCredit" value="<?php echo ($row['ugProfitCredit']>0 && $this->item['pProfitCredit']>0) ? round(($row['ugProfitCredit']/$this->item['pProfitCredit']*100),2) : 0;?>" onkeyup="calcMoney(this.value,<?php echo $row['uId'];?>);" />
									<span class="input-group-addon">%</span>
								</div>
								<span class="help-block" id="money<?php echo $row['uId'];?>"><small><?php if($row['ugProfitCredit']>0) echo "<font color=red>(".number_format($row['ugProfitCredit'],0,'.',',')." VNĐ)</font>"; ?></small></span>
							</div>
						</div>
						<?php } ?>
						<?php if(check_permission('project_salary_edit')){ ?>
						<div class="form-group">
							<label class="col-lg-4 control-label"><?php echo $this->language['project_salary_push_month'];?></label>
							<div class="col-lg-8">
								<select name="pushMonth" id="pushMonth" class="form-control control-inline">
									<?php for($i=1; $i <= 12;$i++){ ?>
									<option value="<?php echo $i;?>" <?php if($i == date("n",time())){ echo "selected";}?>>Tháng <?php echo $i;?></option>
									<?php } ?>
								</select>
								<select name="pushYear" id="pushYear" class="form-control control-inline">
									<?php for($i=2013; $i <= 2020;$i++){ ?>
									<option value="<?php echo $i;?>" <?php if($i == date("Y",time())){ echo "selected";}?>><?php echo $i;?></option>
									<?php } ?>
								</select>
							</div>
						</div>
						<div class="form-group">
							<div class="col-lg-offset-4 col-lg-8">
								<button class="btn btn-primary" type="submit"><?php echo $this->language['update'];?></button>
								<button class="btn btn-danger" onClick="pushSalary();"><?php echo $this->language['project_salary_push'];?></button>
							</div>
						</div>
						<?php } ?>
					</form>
					<script>
						function calcMoney(money,id){
							var profit = $("#pProfitCredit").autoNumericGet();
							var mn = Math.ceil((money*profit/100)/1000)*1000;
							$("#money"+id).html("<font color=red>("+formatCurrency(mn)+" VNĐ)</font>").fadeIn();
						}
					</script>
				</div>
			</div>
		</div>
		<div class="col-lg-8">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-money"></i> <?php echo $this->language['salary_pushed'];?></div>
				</div>
				<div class="panel-body">
					<?php if(count($this->salary_tmp_parent)>0){
					$total = 0;
					foreach($this->salary_tmp_parent as $parent){
					echo "<h3>Lương chia ngày : ".date("d/m/Y",$parent['tmp_create_date'])." <a href='javascript:;' onClick=\"removePushSalary('".$parent['tmp_create_date']."');\">[Xóa]</a></h3>";?>
					<table class="table table-fixed table-hover table-condensed">
						<tbody>
							<?php foreach($this->salary_tmp as $row){ if($row['tmp_create_date'] == $parent['tmp_create_date']){
							if(check_permission('project_view', $_SESSION['uPermission'])){ ?>
							<tr>
								<td><a href="#user_view/uId=<?php echo $row['uId'];?>"><?php echo $row['uFullname'];?></a></td>
								<td style="width:130px;"><font color=red><?php echo number_format($row['tmp_amount'],0,',','.');?> VNĐ</font></td>
							</tr>
							<?php }elseif($row['uId'] == $_SESSION['userId']){ ?>
							<tr>
								<td><a href="#user_view/uId=<?php echo $row['uId'];?>"><?php echo $row['uFullname'];?></a></td>
								<td style="width:130px;"><font color=red><?php echo number_format($row['tmp_amount'],0,',','.');?> VNĐ</font></td>
							</tr>
							<?php }}} ?>
						</tbody>
					</table>
					<?php } ?>
					<h3><?php echo $this->language['summary'];?></h3>
					<table class="table table-fixed table-hover table-condensed">
						<tbody>
							<?php foreach($this->salary_total as $row){ if(check_permission('project_view')){
								$total = $total + $row['tmp_amount'];  ?>
							<tr>
								<td><a href="#user_view/uId=<?php echo $row['uId'];?>"><?php echo $row['uFullname'];?></a></td>
								<td style="width:130px;"><font color=red><?php echo number_format($row['tmp_amount'],0,',','.');?> VNĐ</font></td>
							</tr>
							<?php }elseif($row['uId'] == $_SESSION['userId']){
								$total = $total + $row['tmp_amount']; ?>
							<tr>
								<td><a href="#user_view/uId=<?php echo $row['uId'];?>"><?php echo $row['uFullname'];?></a></td>
								<td style="width:130px;"><font color=red><?php echo number_format($row['tmp_amount'],0,',','.');?> VNĐ</font></td>
							</tr>
							<?php }} ?>
						</tbody>
						<tfoot>
							<tr>
								<td><?php echo $this->language['salary_total_pushed'];?></td>
								<td style="width:130px;"><font color=red><?php echo number_format($total,0,',','.');?> VNĐ</font></td>
							</tr>
						</tfoot>
					</table>
					<?php }else{ ?>
					<div class="alert alert-info"><?php echo $this->language['salary_not_have'];?></div>
					<?php } ?>
				</div>
			</div>
		</div>
	</div>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
	<script type="text/javascript">
		$(function() {
			$("#title-header").text('<?php echo $this->title_header;?>');
			$("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
		});
	</script>
<?php endif;?>
<?php
	if($_REQUEST['ajax']!=true) include 'footer.tpl.php';
?>